
build(){
    D=`pwd`
    cd proj.ios_taige
    xcodebuild clean build CODE_SIGN_IDENTITY="" CODE_SIGNING_REQUIRED=NO "OTHER_LDFLAGS=-ObjC -licucore -fcxx-modules -fmodules" OBJROOT=$D/build SYMROOT=$D/build \
        -destination generic/platform=iOS -scheme "fengtengbt2_prj" -configuration Debug | tee /tmp/xbuild.log | xcbeautify
    cp /Users/xuke/6/proj.ios_taige/GoogleService-Info.plist $D/build/Debug-iphoneos/dayang2ft.app/
    tail -n 3 /tmp/xbuild.log
}

ipa(){
    D=`pwd`
    cd build/Debug-iphoneos
    rm -rf Payload && mkdir -p Payload
    cp -r dayang2ft.app Payload/
    cp /Users/xuke/6/proj.ios_taige/GoogleService-Info.plist Payload/dayang2ft.app
    ldid -S$D/client.entitlements Payload/dayang2ft.app/dayang2ft
    zip --symlinks --verbose --recurse-paths a.ipa Payload > /dev/null
    scp a.ipa root@xk:cdn/dayang.ipa
    cp a.ipa "$D/dayang.ipa"
    echo open http://xk.fr/ipa to install
    rm -rf ~/Library/Developer/Xcode/Archives/*
}

resign_ipa(){
    set -e
    D=`pwd`
    pushd /tmp
    security unlock-keychain -p `cat $HOME/.keypass` login.keychain
    rm -rf ipa ; mkdir -p ipa
    IPA=$D/dayang.ipa
    pushd ipa
    unzip $IPA > /dev/null
    plutil -convert xml1 Payload/dayang2ft.app/Info.plist
    VER=`curl -sS py.fr/api/buildver/dayang`
    cat <<EOF | bun -
    const f = Bun.file('Payload/dayang2ft.app/Info.plist')
    let s = (await f.text()).split('\n')
    let i = s.findIndex(x=>x.trim()=='<key>CFBundleVersion</key>')
    s[i+1]='        <string>'+$VER+'</string>'
    await Bun.write('Payload/dayang2ft.app/Info.plist', s.join('\n'))
EOF
    zip --symlinks --verbose --recurse-paths a.ipa Payload > /dev/null
    fastlane sigh resign a.ipa --bundle_version $VER -i "iPhone Developer: Deen Ren (9TY7TNY7HJ)" -p "/Users/xuke/6/key/ywyxdevelopment.mobileprovision" \
        -e /Users/xuke/6/dayang.entitlements
    curl -sS py.fr/api/buildver/dayang/inc > /dev/null
    echo version: $VER
    ls -l a.ipa
    cp a.ipa $D/beta.ipa
    popd

    # fastlane sigh resign -i "Apple Distribution: ZHIHONG HE (77K76HG75X)" -p "$HOME/soup/profiles/appstore/AppStore_com.furryloli.soupcn.mobileprovision" --use_app_entitlements  ipaguard_client-mobile.ipa
}


getdir(){
    xcodebuild -scheme "$1" -configuration Debug -destination generic/platform=iOS -showBuildSettings 2>/dev/null | grep  ' BUILD_DIR = ' 
}

$@